package com.itheima.controller;

import com.itheima.pojo.Bookshelf;
import com.itheima.pojo.Category;
import com.itheima.pojo.Result;
import com.itheima.service.BookShelfService;
import com.itheima.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/bookshelf")
public class BookShelfController {
    @Autowired
    private BookShelfService bookShelfService;
    //    @Validated(Category.Add.class)
    @PostMapping
    public Result add(@RequestBody Bookshelf bookshelf){
        bookShelfService.addBookShelf(bookshelf);
        return Result.success();
    }

    @GetMapping
    public Result<List<Bookshelf>> list(){
        List<Bookshelf> cs = bookShelfService.list();
        return Result.success(cs);
    }

//    @GetMapping("/detail")
//    public Result<Category> detail(Integer id){
//        Category c = categoryService.findById(id);
//        return Result.success(c);
//    }

    @PutMapping
    public Result update(@RequestBody Bookshelf bookshelf){
        bookShelfService.updateBookShelf(bookshelf);
        return Result.success();
    }

    @DeleteMapping
    public Result delete(Integer id){
        bookShelfService.deleteBookShelf(id);
        return Result.success();
    }
}
